The present invention relates to a microprocessor and, more particularly, to a technique for performing high-speed processing of instructions (to be referred to as bit field operation instructions hereinafter) to perform extraction, insertion, and comparison of consecutive bit strings (to be referred to as bit fields hereinafter) in word data.
A microprocessor has bit field operation instructions, as macro instructions, to perform extraction, insertion, and comparison of bit fields. In a conventional system, bit field operation instructions are executed by operating a barrel shifter using a microprogram. FIG. 4 shows a conventional barrel shifter. Referring to FIG. 4, reference numeral 101 denotes a data bus in a microprocessor; 102 and 103, registers (to be respectively referred to as an SFT0 and an SFT1 hereinafter) for holding input data; 104, a selector (to be referred to as a BSEL hereinafter) as a main body of the barrel shifter; 105, a register (to be referred to as an SFTOUT hereinafter) for holding output data from the barrel shifter; 106, a control section of the barrel shifter; 107, a microinstruction latch (to be referred to as an MI hereinafter) for storing microinstructions to operate the control section 106; 108, a register (to be referred to as an SFTOP hereinafter) for holding a shift amount to be supplied to the barrel shifter; 109, a register (to be referred to as an SFTOPR hereinafter) for holding various types of shift operations (e.g., "logic left shift", "logic right shift", "arithmetic left shift", "arithmetic right shift", "left rotate", and "right rotate"); 110, select information (to be referred to as an SFTSL hereinafter) to be generated for the BSEL 1-4 in accordance with values held in the SFTOP 108 and the SFTOPR 109; and 111 and 112, strobe signals (to be respectively referred to as an SFT0WR and an SFT1WR hereinafter) used to latch the value of the data bus 101 in the SFT0 102 and the SFT1 103.
When a shift operation is to be performed in the barrel shifter in FIG. 4, values are respectively set in the SFT0 102, the SFT1 103, the SFTOP 108, and the SFTOPR 109, and data is read out from the SFTOUT 105 at a predetermined timing by using a microprogram. FIG. 5 shows a microprogram used to perform a shift instruction in the barrel shifter in FIG. 4. Referring to FIG. 5, the following operations are performed in the respective steps:
First step: setting a shift amount COUNT in the SFTOP 108, and setting a shift type in the SFTOPR 109 PA1 Second step: setting data SRC (to be shifted) in the SFT0 102 and the SFT1 103 PA1 Third step: extracting a shift result from the SFTOUT 105, storing it in a destination DST, and terminating the microprogram
Referring to FIG. 5, "SFTOPR" is a control instruction to set a value in the SETOPR 109 shown in FIG. 4. More specifically, "SFTOPR" includes: SHL . . . logic left shift; SHR . . . logic right shift; SAL . . . arithmetic left shift; SAR . . .arithmetic right shift; ROL . . . left rotate; and ROR . . . right rotate.
In addition, referring to FIG. 5, "END" represents the end of a microprogram, and "="represents transfer of data to a register. In this case, "SFTIN"in the second step is a virtual register for indirectly designating the SFT0 102 and the SFT1 103. The value of the data SRC (to be shifted) is stored in the SFT0 102 and the SFT1 103 in accordance with the value of the SFTOPR 109, as shown in FIG. 7. Note that in the microprogram, values can be independently set in the SFT0 102 and the SFT1 103. In this case, "SFT0" and SFT1" are to be described in the microprogram in place of "SFTIN".
FIG. 6 is a timing chart of the barrel shifter in the execution of the microprogram shown in FIG. 5. Signal names in FIG. 6 correspond to signal names in FIG. 4, although "CLOCK", "SFTUOP", and "SFTDIR" are not shown in FIG. 4. "CLOCK" indicates a clock. "SFTUOP" is the absolute value of "SFTOP". If the value of "SFTOP" is negative, it indicates a shift direction (left or right) opposite to a direction designated by "SFTOPR". "SFTDIR" indicates a final shift direction determined by the signs of "SFTOPR" and "SFTOP". In this conventional system, the positive/negative sign of "SFTOP" influences a shift direction. Otherwise, "SFTDIR" is directly determined by "SFTOPR", and "SFTUOP" and "SFTOP" are set to be the same value. However, such a difference is not an essential matter. Referring to FIG. 4, the BSEL 104 regards the SFT0 102 and the SFT1 103 as linked data of two words (e.g., 64 bits), extracts consecutive one-word data (e.g., 32 bits) from a specific bit position in the two-word data, and stores it in the SFTOUT 105. This one-word data is determined in accordance with the values of "SFTUOP" and "SFTDIR", as shown in FIG. 8.
Bit field operation instructions can be performed by the above-described barrel shifter. Three types of operations, i.e., "extract", "insert", and "compare", can be considered as bit field operations. In this case, insertion of a bit field will be considered as an example. Bit field insertion is an operation of inserting data of consecutive several bits (LEN bits) extracted from one-word data SRC in a range of consecutive LEN bits starting from a given bit position (bit BIT) of another one-word data DST. Assume, in this case, that lower LEN bit data is extracted from the data SRC to be inserted in the data DST. In this case, insertion of a bit field can be performed by the barrel shifter in accordance with a procedure shown in FIG. 9. FIG. 10 shows a microprogram which describes this procedure. FIG. 11 is a timing chart of the execution of the microprogram. Referring to FIG. 11, the value of "SFTOUT", which is changed three times, is read out in the minimum procedure. This is the minimum procedure for inserting a bit field. That is, the minimum procedure for bit field insertion using the conventional barrel shifter has 6 steps (6 clocks), as shown in FIG. 10.
As described above, bit field insertion using the conventional barrel requires at least 6 clocks. In practice, however, a microprogram is required to perform exception detection and the like as well as an operation of a barrel shifter. For this reason, it is difficult to perform bit field insertion using only 6 clocks. In addition, with recent applications to a postscript operation of a microprocessor and a laser printer, bit field operation instructions are required to be executed at higher speed. High-speed bit field operations cannot be performed by using the conventional barrel shifter.